<template>
	<view>
		<view class="cart-container" v-if="cart.length !== 0">
			<view>
			<my-address></my-address>
		</view>
			<!-- 标题内容 -->
			<view class="cart-title">
				<uni-icons type="shop" size="18"></uni-icons>
				<text class="cart-title-text">购物车</text>
			</view>
			<!-- 列表 -->
			<uni-swipe-action>

				<!-- <uni-swipe-action-item :options="" @click=""></uni-swipe-action-item> -->
				<block v-for="(item, index) in cart" :key="index">
					<uni-swipe-action-item :right-options="option" @click="swipeActionHandler(item)">
						<my-goods :goods="item" :showRadio="true" @rchange="radioChangeHandler" :showNumber="true"
							@num-change="numChangeHandler"></my-goods>
					</uni-swipe-action-item>
				</block>
			</uni-swipe-action>

			<!-- 结算区域 -->
			<my-settle></my-settle>
		</view>

		<!-- 空白购物车区域 -->
		<view class="empty-cart" v-else>
			<image src="" class="empty-img"></image>
			<text class="tip-text">至少要加入一件商品再走吧，亲~~~</text>
		</view>
	</view>
</template>

<script>
	import badgeMix from '@/mixins/tabbar-badge.js'
	import { mapGetters, mapState, mapMutations } from 'vuex'
	export default {
		data() {
			return {
				option: [{
					text: '删除', // 显示的文本內容
					style: {
						backgroundColor: '#c00000' // 按钮的背景颜色
					}
				}]
			};
		},
		mixins: [badgeMix],
		computed: {
			...mapState('myCart', ['cart'])
		},
		methods: {
			...mapMutations('myCart', ['radioClickChange', 'numClickChange', 'removeGoodsCartItem']),
			// 商品的勾选按钮发生变化
			radioChangeHandler(val) {
				this.radioClickChange(val)
				// console.log(val);
			},
			// 商品的数量发生变化
			numChangeHandler(val) {
				this.numClickChange(val)
			},
			// 点击了滑动的操作按钮
			swipeActionHandler(item) {
				this.removeGoodsCartItem(item.goods_id)
			}
		// computed: {
		// 	...mapGetters('myCart', ['total'])
		// },
		// onShow() {
		// 	this.setBage()
		// },
		// methods: {
		// 	setBage() {
		// 		uni.setTabBarBadge({ //为tabBar右上角设置徽标
		// 			index: 2,
		// 			text: this.total + '' // text的值必须是字符串，不能是数字
		// 		})
		// 	}
		// }
	}
}
</script>

<style lang="scss">
	.cart-title {
		height: 40px;
		display: flex;
		align-items: center;
		font-size: 14px;
		padding-left: 5px;
		border-bottom: 1px solid #d0d0d0;

		.cart-title-text {
			margin-left: 10px;
		}
	}

	.empty-cart {
		display: flex;
		flex-direction: column;
		align-items: center;
		padding-top: 15px;

		.empty-img {
			width: 90px;
			height: 90px;
		}

		.tip-text {
			font-size: 12px;
			color: gray;
			margin-top: 15px;
		}
	}
</style>